package demo1107.demo02;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/11/7 16:07
 */
public class Test03 {
    public static void main(String[] args) {
        Singleton2 i1 = Singleton2.getInstance();
        Singleton2 i2 = Singleton2.getInstance();
        System.out.println(i1);
        System.out.println(i2);
    }
}
class Singleton2{

    private Singleton2(){}

    private static Singleton2 singleton2;

    public static Singleton2 getInstance(){
        if (singleton2==null){
            synchronized (Singleton2.class){
                if (singleton2==null){
                    singleton2=new Singleton2();
                }
            }
        }
        return singleton2;
    }
}